package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.entity.NursingProject;
import com.zzyl.service.NursingService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description nursingController
 * @Author liangDong
 * @Date 2025-05-07  20:25
 */
@RestController
@RequestMapping("/nursing_project")
@Api("护理模块")
public class NursingProjectController extends BaseController{
    @Autowired
    private NursingService nursingService;

    @GetMapping
    public ResponseResult<PageResponse<NursingProjectVo>> page(
            @RequestParam(value = "name",required = false) String name,
            @RequestParam(value = "status" , required = false) Integer status,
            @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize)
    {
        PageResponse<NursingProjectVo> nursingProjectPageInfo = nursingService.page(name,status,pageNum,pageSize);
        return success(nursingProjectPageInfo);
    }

    @PostMapping
    public ResponseResult addNursingProject(@RequestBody NursingProjectVo nursingProjectVo){
        nursingService.add(nursingProjectVo);
        return success();
    }

    @GetMapping("/{id}")
    public ResponseResult<NursingProjectVo> getNursingProjectById(@PathVariable Long id){
        NursingProjectVo nursingProjectvo = nursingService.getById(id);
        return success(nursingProjectvo);
    }

    @PutMapping
    public ResponseResult updateNursingProject(@RequestBody NursingProjectVo nursingProjectVo){
        nursingService.update(nursingProjectVo);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    public ResponseResult updateStatus(@PathVariable Long id, @PathVariable Integer status){
        nursingService.updateStatus(id,status);
        return success();
    }

    @DeleteMapping("/{id}")
    public ResponseResult deleteNursingProjectById(@PathVariable Long id){
        nursingService.deleteById(id);
        return success();
    }

    /*
    *
    * 用来实现护理计划选择项目的下拉框
    * */
    @GetMapping("/all")
    public ResponseResult getAllNursingProject(){
         List<NursingProject> list =  nursingService.getAll();
        return success(list);
    }


}
